<?if (!defined('DORB')) die('Security: Verzoek om script uit te voeren geweigerd (onveilige bron).');

	$ritplaatsenForm = new Form('ritplaatsenForm');
	
	$ritplaatsenForm->add(new FormElement('vrachtwagen','text'));
	$ritplaatsenForm->add(new FormElement('oplegger','text'));
	$ritplaatsenForm->add(new FormElement('chauffeur','text'));
	//array( $r = $mysqli->query('select email from gebruiker '); if (!$r) echo $mysqli->error;));

	$r=$mysqli->query('SELECT v.ID as vrachtid,pallets,v.datum,vt.type as vrachttype FROM vrachten v LEFT JOIN ritten_vrachten rv ON v.ID=rv.vracht LEFT JOIN vrachttype vt ON v.vrachttype=vt.ID WHERE rv.rit IS NULL');
	$ongeplandeOrders = array();
	while ($row=$r->fetch_assoc())
	{
		if (empty($row['vrachtid'])) continue;
		
		$ongeplandeOrders[$row['vrachtid']] = "#" . $row['vrachtid'] . " " . $row['pallets'] . " x " . $row['vrachttype'] . " " . $row['datum'] ; 
	}
	
	$ritplaatsenForm->add(new FormElement('orders','multiple',null,null,null,$ongeplandeOrders));
	

	require_once('handler.php');
	
	if (	!has_permission('MAG_PLAATSEN_RITTEN') 
		 || !has_permission('MAG_PORTAL_GEBRUIKEN'))
	{
		setLastFormResult(0,'403: u heeft niet de behorende machtiging deze pagina te bekijken');
		redirect('main');
	}
	
	
	echo menu();
?>
<div id="content-container" >
<div class="content">
<?getLastFormResultHTML()?>
<?$ritplaatsenForm->show()?>
<p>Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</p>

</div>
</div>

<script>

 $.widget( "custom.catcomplete", $.ui.autocomplete, {
        _renderMenu: function( ul, items ) {
            var that = this,
                currentCategory = "";
            $.each( items, function( index, item ) {
                if ( item.category != currentCategory ) {
                    ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                    currentCategory = item.category;
                }
                that._renderItemData( ul, item );
            });
        }
    });

<? $r=$mysqli->query('SELECT * FROM oplegger o LEFT JOIN vrachttype vt ON o.vrachttype=vt.ID WHERE beschikbaar=1')?>
var opleggers = [<?while($row=$r->fetch_assoc()) echo '{ label: "' . $row['kenteken'] . '", category: "' . $row['type'] . '"},'?>];

<? $r=$mysqli->query('SELECT * FROM vrachtwagen WHERE beschikbaar=1')?>
var vrachtwagens = [<?while($row=$r->fetch_assoc()) echo '{ label: "' . $row['kenteken'] . '", category: ""},'?>];

<? $r=$mysqli->query('SELECT * FROM gebruiker g LEFT JOIN gebruikerrollen gr ON gr.gebruiker=g.email LEFT JOIN bedrijf b ON g.bedrijf=b.ID WHERE gr.rol="ChauffeurDorb" OR gr.rol="ChauffeurExtern" ORDER BY bedrijf')?>
var chauffeurs = [<?while($row=$r->fetch_assoc()) echo '{ label: "' . $row['email'] . '", category: "' . $row['naam'] . '"},'?>];
		
	$('[name=vrachtwagen]').catcomplete({delay: 0,source: vrachtwagens});	
	$('[name=oplegger]').catcomplete({delay: 0,source: opleggers});
	$('[name=chauffeur]').catcomplete({delay: 0,source: chauffeurs});
</script>
